/*
 * @Description: array
 * @Author: rendc
 * @Date: 2022-09-28 10:05:17
 * @LastEditors: rendc
 * @LastEditTime: 2022-09-29 09:14:31
 */
// 数组字面量
var arr = [1, 2, 3]
console.log('🤡 CC - arr', arr.length);
var arr = [1, , 3]
console.log('🤡 CC - arr', arr.length);
var arr = [1, , 3, ,]
console.log('🤡 CC - arr', arr.length);
console.log('🤡 CC - arr', arr[1]);
// 构造函数
let arr1 = new Array();
console.log('🤡 CC - arr1', arr1); // []
let arr2 = new Array(20); // 指定数组长度 
console.log('🤡 CC - arr2', arr2);
console.log('🤡 CC - arr2', arr2[0]); // undefined
let arr3 = new Array(1, 2, 3); // 指定数组内容
let arr5 = [, , ,]
console.log('🤡 CC - arr5', arr5[0]);
let arr4 = new Array(', , '); // 指定数组内容
console.log('🤡 CC - arr4', arr4);
console.log('🤡 CC - arr3', arr3);
console.log('🤡 CC - arr3', arr3[100]);
arr3[0] = 0
arr3[1] = 1
arr3[2] = 2
console.log('🤡 CC - arr3', arr3);
arr3[10] = 10
console.log('🤡 CC - arr3', arr3);
let obj = {}
console.log(typeof arr3); // object
console.log(obj instanceof Array);
console.log(arr3 instanceof Array);
console.log(Array.isArray(arr3));

// 增加
// 1. arr3[10] = 10
// 2. push()
var result = arr1.push("1", "2", "3");
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr1', arr1);
// 3. unshift
var result = arr1.unshift("0");
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr1', arr1);
// 删除
// 1. length = 0
var length = arr1.length;
console.log('🤡 CC - length', length);
console.log('🤡 CC - arr1', arr1);
arr1.length = 3
var length = arr1.length;
console.log('🤡 CC - length', length);
console.log('🤡 CC - arr1', arr1);
// 2. pop
var result = arr1.pop();
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr1', arr1);
// 3. shift
var result = arr1.shift();
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr1', arr1);

// 数组序列化
var arr = [1, 2, 3, 4, 5];
console.log(arr.toString()); // 以逗号分割字符串的形式返回数组项
console.log(arr.join("-")); // 以指定的字符来分割数组的字符串
console.log(arr.join("|"));
console.log('🤡 CC - arr', arr);

// 排序
var result = arr.reverse();
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = ['苹果', '桔子', '葡萄']
console.log('🤡 CC - arr', arr);
var result = arr.reverse();
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = [2, 4, 5, 3, 1, 0, 11, 22, 33]
console.log('🤡 CC - arr', arr);
var result = arr.sort();
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);



var arr = [1, 2, 3, 4, 5,];
console.log('🤡 CC - arr', arr);
var result = arr.concat([6, 7, 8]);
var result = arr.concat(9);
var result = arr.concat(10, 11);
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = [1, 2, 3, 4, 5,];
console.log('🤡 CC - arr', arr);
var result = arr.slice(2);
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log('🤡 CC - arr', arr);
var result = arr.slice(5); // 6, 7, 8, 9, 10
// var result = arr.slice(0, 5); // 1, 2, 3, 4, 5,
// var result = arr.slice(1, 5); //2, 3, 4, 5,
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);


var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log('🤡 CC - arr', arr);
var result = arr.splice(3, 5); //[4, 5, 6, 7, 8]  [1, 2, 3, 9, 10]
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log('🤡 CC - arr', arr);
var result = arr.splice(5, 0, 777); //[1, 2, 3, 4, 5,777, 6, 7, 8, 9, 10
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log('🤡 CC - arr', arr);
var result = arr.splice(5, 3, 777); //[1, 2, 3, 4, 5,777, 9, 10]
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log('🤡 CC - arr', arr);
var result = arr.splice(5, 3, "6", "7", "8"); // [1, 2, 3, 4, 5, "6", "7", "8", 9, 10]
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

// 查找
var arr = [1, 2, 3, 4, 5, 2];
console.log('🤡 CC - arr', arr);
var result = arr.indexOf(2, 5);
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);

// 查找
var arr = [1, 2, 3, 4, 5, 2];
console.log('🤡 CC - arr', arr);
var result = arr.lastIndexOf(2);
console.log('🤡 CC - result', result);
console.log('🤡 CC - arr', arr);